package com.compty.security.web;

import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.compty.paint.util.Constants;
import com.compty.security.domain.Menu;



/**
 * 权限标签
 * 用法：
 * <%@ taglib uri="/tag" prefix="auth" %>  
 * <auth:showmenu url="abc">内容</auth:showmenu>
 * 如果内容对应的url在权限范围，则显示内容。否则，不显示内容
 * @author zhuqh
 *
 */
public class AuthenticationTag extends TagSupport {

	private static final long serialVersionUID = 149276247185833634L;
	
	private String menuName;

	@Override
	public int doEndTag() throws JspException {
		// TODO Auto-generated method stub
		return super.doEndTag();
	}

	@SuppressWarnings("unchecked")
	@Override
	public int doStartTag() throws JspException {
		//取权限列表
		 Map<String,Menu> map  = (Map<String, Menu>) pageContext.getSession().getAttribute(Constants.MenuMap);
		
		if(map != null && map.containsKey(menuName)) { //包含权限，显示内容
			return TagSupport.EVAL_BODY_INCLUDE;
		}else {  //否则跳过
			return TagSupport.SKIP_BODY;
		}
	}

	public String getMenuName() {
		return menuName;
	}

	public void setMenuName(String menuName) {
		this.menuName = menuName;
	}
	
}

